<template>
  <div class="success">
    <img :src="require(`../../../../public/img/email/${isTime?'successTime':'mailSuccess'}.png`)" alt="">
    <p>邮件已为您保存至
      <span v-if="!isTime" @click="move('/mail/send/index')">[已发送]</span>
      <span v-else @click="move('/mail/draft/index')">[草稿箱]</span>
    </p>
    <div class="btn">
      <el-button type="primary" @click="toDetail" v-show="!result.monocular"><i class="icon-review"></i> 查看此件
      </el-button>
      <el-button type="primary" @click="move('/mail/write/index')"><i class="el-icon-edit"></i> 继续写信</el-button>
    </div>
  </div>
</template>

<script>
    import {getDiffList,removeCurrentTab} from '@/util/util'
    import {mapState} from 'vuex'
    export default {
        name: "success",
        props:['currentID'],
        data() {
            return {
                isTime: false,
                result: {},
                target:''
            }
        },
        computed: {
            ...mapState(['common'])
        },
        methods: {
            init(params) {
                this.result = params;
                if (params.name == 'emailListTab') {//收件箱
                    this.target = 'SET_EMAILLISTTAB'
                } else if (params.name == 'emailListUnreadTab') {//未读信箱
                    this.target = 'SET_EMAILLISTUNREADTAB'
                } else if (params.name == 'emailListOutTab') {//已发送箱
                    this.target = 'SET_EMAILLISTOUTTAB'
                }else  if(params.name=='emailListPendingTab'){//待处理
                    this.target = 'SET_EMAILLISTPENDINGTAB'
                }
                this.isTime = this.result.emailSendTiming != '';
            },
            //查看此件
            toDetail() {
                //关闭当前窗口
                removeCurrentTab(this.result.name,this.target,this.currentID);
                if (this.isTime) {//定时发送
                    sessionStorage.setItem("lastpath", '/mail/draft/index')
                    this.$store.commit('SET_ISFRAG', 2)
                    this.$router.push({
                        path: '/mail/edit',
                        query: {
                            id: this.result.id
                        }
                    })
                } else {//普通 - 已发送详情
                    const ID = this.result.id.toString();
                    if (getDiffList(ID, 'emailListOutTab') == -1) {
                        this.$store.commit('SET_EMAILLISTOUTTAB', {
                            type: 1, row: {
                                id: ID,
                                title: this.result.title,
                                state: 1,
                                close: true
                            }
                        })
                    } else {
                        this.$store.commit('SET_EMAILLISTOUTTAB', {type: 0, current: ID})
                    }
                    this.$store.commit('SET_ISFRAG', 3)
                    if(this.target != 'SET_EMAILLISTOUTTAB'){//收件箱 - 未读箱 - 待处理 - 需要跳转
                        this.$router.push({
                            path: '/mail/send/index'
                        })
                    }
                }
            },
            move(path) {
                if (path == '/mail/send/index') {
                    this.$store.commit('SET_ISFRAG', 3)
                }else if(path=='/mail/write/index'){
                    this.$store.commit('SET_ISFRAG', '')
                } else {
                    this.$store.commit('SET_ISFRAG', 2)
                }
                //关闭当前窗口
                removeCurrentTab(this.result.name,this.target,this.currentID);
                this.$router.push(path);

            }
        }
    }
</script>

<style scoped lang="scss">
  .success {
    text-align: center;
    margin-top: 170px;

    p {
      line-height: 34px;
      border-radius: 10px;
      color: #232323;
      margin: 20px auto !important;
      width: 322px;
      background-color: #E9F3FD;

      span {
        color: #2A97F9;
        cursor: pointer;
      }
    }

    .btn {
      button {
        width: 129px;
        text-align: center;
        height: 34px;
        line-height: 34px;
        background: rgba(42, 151, 249, 1);
        border-radius: 10px;
        font-size: 14px;
        padding: 0;
      }
    }
  }
</style>
